﻿using System;
using System.Data;
using System.Windows.Forms;
using SystemCustomers.DBUtils;
using SystemCustomers.MessageUtils;

namespace SystemCustomers.ManagePriority
{
    public partial class ViewingPriority : Form
    {
        public ViewingPriority()
        {
            InitializeComponent();
            InitializeListPriority();
        }

        public string IdPriorityFromGrid { get; set;}

        private void ViewingPriority_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.Close();
                this.Dispose();
                GC.Collect();
            }
        }

        private void InitializeListPriority()
        {
            dgridvListPriority.DataSource = SingletonManagerDb.Instance.DbViewingPriority();
        }

        private void addRowToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new AddPriority().ShowDialog();
            InitializeListPriority();
        }

        private void deleteRowToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dgridvListPriority.SelectedRows.Count != 1) return;
            string message = "?בטוח שאתה רוצה למחוק";
            string titel = "מחיקת עדיפות";
            if (new MessageBoxText(message,titel).YesorNoMessageBox() != DialogResult.OK)return;
            DataGridViewRow dr = dgridvListPriority.SelectedRows[0];
            this.IdPriorityFromGrid = dr.Cells["idPriority"].Value.ToString();
            if (!SingletonManagerDb.Instance.DeletePriority(this.IdPriorityFromGrid)) return;
            LogUtils.WriteToLog(" Delete Priority ");
            LogUtils.SystemEventLogsWarning(" Delete Priority");
            InitializeListPriority();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LogUtils.WriteToLog(" Exit Viewing Priority ");
            LogUtils.SystemEventLogsInformation(" Exit Viewing Priority");
            this.Close();
            this.Dispose();
            GC.Collect();
        }

        private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
        {
            InitializeListPriority();
        }
    }
}
